<?php

namespace Coldwind;

/**
 * @author ZXZ <zxz054321@163.com>
 */
class LetParametersFly {

    private static $_parameters = array();

    public static function register($urlParameter) {
        in_array($urlParameter, static::$_parameters) || static::$_parameters[] = $urlParameter;
    }

    public static function unregister($urlParameter) {
        unset(static::$_parameters[$urlParameter]);
    }

    public static function flyWithParameters($u, $vars = null, $echo = TRUE) {
//        dump(static::$_parameters);exit;
        $getString = '';
        foreach (static::$_parameters as $parameter) {
//            dump(I('get.' . $parameter, ''));
            $getString.=$parameter . '=' . I('get.' . $parameter, '') . '&';
//            dump($getString);
        }

        is_null($vars) || $getString.=$vars;

        $url = U($u, $getString);
//        dump($echo);
        if ($echo) {
            echo $url;
        } else {
            return $url;
        }
    }

}
